package com.cyj.dream.admin.contacts.enums;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public enum DataCommonEnum {
    //公共的状态信息
    VALID(GroupEnum.VALID,"VALID","1", 1,"有效"),
    INVALID(GroupEnum.VALID,"INVALID","0", 0,"无效"),

    CHARGE_TASK(GroupEnum.TASK_DIMENSION,"CHARGE_TASK","CHARGE_TASK",1,"我负责的"),
    CONFIRM_TASK(GroupEnum.TASK_DIMENSION,"CONFIRM_TASK","CONFIRM_TASK",2,"我确认的"),
    ASSIGN_TASK(GroupEnum.TASK_DIMENSION,"ASSIGN_TASK","ASSIGN_TASK",3,"我指派的"),

    MY_TASK(GroupEnum.TASK_TYPE,"MY_TASK","MY_TASK",1,"我的任务"),
    TODAY_TASK(GroupEnum.TASK_TYPE,"TODAY_TASK","TODAY_TASK",2,"今日新增"),
    ARCHIVING_TASK(GroupEnum.TASK_TYPE,"ARCHIVING_TASK","ARCHIVING_TASK",3,"归档任务"),
    OVERDUE_TASK(GroupEnum.TASK_TYPE,"OVERDUE_TASK","OVERDUE_TASK",4,"逾期任务"),


    UN_ARCHIVING(GroupEnum.ARCHIVING_STATUS,"UN_ARCHIVING","0",0,"任务未归档"),
    ARCHIVING(GroupEnum.ARCHIVING_STATUS,"ARCHIVING","1",1,"任务已归档"),


    TASK_STATUS_0(GroupEnum.TASK_STATUS,"TASK_STATUS_0","0",0,"未开始"),
    TASK_STATUS_1(GroupEnum.TASK_STATUS,"TASK_STATUS_1","1",1,"进行中"),
    TASK_STATUS_2(GroupEnum.TASK_STATUS,"TASK_STATUS_2","2",2,"完成待确认"),
    TASK_STATUS_3(GroupEnum.TASK_STATUS,"TASK_STATUS_3","3",3,"已确认"),

    OVERDUE(GroupEnum.OVERDUE_STATUS,"OVERDUE","1",1,"已经逾期"),
    UN_OVERDUE(GroupEnum.OVERDUE_STATUS,"UN_OVERDUE","2",2,"未逾期"),

    VIEW_ONGOING_PROJECT(GroupEnum.PROJECT_VIEW_TYPE,"ONGOING_PROJECT","1",1,"进行中"),
    VIEW_ALL_PROJECT(GroupEnum.PROJECT_VIEW_TYPE,"ALL_PROJECT","2",2,"全部项目"),
    VIEW_FILED_PROJECT(GroupEnum.PROJECT_VIEW_TYPE,"VIEW_FILED_PROJECT","3",3,"归档项目"),

    UN_STARTED(GroupEnum.PROJECT_STATUS,"UN_STARTED","1",1,"未开始"),
    ONGOING(GroupEnum.PROJECT_STATUS,"ONGOING","2",2,"进行中"),
    FINISHED(GroupEnum.PROJECT_STATUS,"FINISHED","3",3,"已结束"),
    FILED(GroupEnum.PROJECT_STATUS,"FILED","4",4,"已归档"),

   ;

    @Getter
    @Setter
    private GroupEnum groupEnum;

    @Getter
    @Setter
    private String code, value, desc;

    @Getter
    @Setter
    private Integer intValue;

    DataCommonEnum(GroupEnum groupEnum,String code,String value,Integer intValue, String desc){
        this.groupEnum = groupEnum;
        this.code = code;
        this.value = value;
        this.intValue = intValue;
        this.desc = desc;
    }


    public static DataCommonEnum parseValue(GroupEnum groupKey, Object code){
        Optional<DataCommonEnum> optional = Arrays.stream(DataCommonEnum.values()).filter(e ->
                Objects.equals(e.groupEnum.getGroupKey(), groupKey.getGroupKey())
              && Objects.equals(String.valueOf(code),e.getCode())
        ).findFirst();

      return optional.isPresent() ? optional.get() : null;
    }

    public static String getDataName(GroupEnum groupKey, Object code) {
        return Optional.ofNullable(parseValue(groupKey, code))
                .map(DataCommonEnum::getDesc)
                .orElse("");
    }


    public enum GroupEnum{

        TASK_DIMENSION("TASK_DIMENSION","任务维度"),

        TASK_TYPE("TASK_DIMENSION","任务类型"),

        ARCHIVING_STATUS("ARCHIVING_STATUS","归档任务"),

        TASK_STATUS("TASK_STATUS","任务状态"),

        VALID("VALID","公共状态"),

        OVERDUE_STATUS("OVERDUE_STATUS","逾期状态状态"),

        PROJECT_VIEW_TYPE("PROJECT_VIEW_TYPE","项目查询列表(进行中/全部任务/归档任务)"),

        PROJECT_STATUS("PROJECT_STATUS","项目状态"),
        ;

        @Getter
        @Setter
        String groupKey, groupName;


        GroupEnum(String groupKey, String groupName){
            this.groupKey =groupKey;
            this.groupName = groupName;
        }

    }




}
